
{extend name='public/window' /}

{block name="content"}
<style>
    .layui-upload-drag {
        position: relative;
        padding: 10px;
        border: 1px dashed #e2e2e2;
        background-color: #fff;
        text-align: center;
        cursor: pointer;
        color: #999;
        border-radius: 50%;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="form">

                <div class="layui-form-item">
                <label class="layui-form-label label-required-next">用户头像：</label>
                    <div class="layui-input-block">
                        <div class="layui-upload-drag">
                            <img id="show_id" class="layui-circle" src="{if isset($info.id)} {$info.avatar} {else} __IMG__/default_upload.png {/if}" alt="上传图片" width="120" height="120">
                            <input type="hidden" id="avatar" name="avatar" value=""   lay-verify="required" lay-verType="tips" lay-reqText="头像没有上传">
                        </div>
                        <div style="margin-top:10px;">
                            <button type="button" class="layui-btn" id="editimg"  width="120"><i class="layui-icon">&#xe67c;</i>上传头像</button>
                        </div>
                        <div class="layui-form-mid layui-word-aux">建议尺寸：150 X 100</div>
                    </div>
                </div>

                {if isset($info.id)}
                <input type="hidden" name="id" value="{$info.id}">
                {/if}

                <input type="hidden" name="__token__" id="token" value="{:token()}"/>

                <div class="layui-form-item">
                    <label class="layui-form-label label-required-next">用户名：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="text" name="username" value="" placeholder="请输入管理员用户名" lay-verify="required" lay-vertype="tips" lay-reqtext="请输入管理员用户名" autocomplete="off" class="layui-input ">
                    </div>
                    <label class="layui-form-label ">管理员昵称：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="text" name="nickname" value="" placeholder="管理员昵称" lay-verify="" lay-vertype="tips" lay-reqtext="请输入管理员昵称" autocomplete="off" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label label-required-next">登录密码：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="password" name="password" value="" placeholder="请输入登录密码" lay-verify="{if !isset($info.id)}required{/if}" lay-vertype="tips" lay-reqtext="请输入登录密码" autocomplete="off" class="layui-input ">
                        {if isset($info.id)}
                        <p class="help-block">不填密码则不修改密码！！！</p>
                        {/if}
                    </div>
                    <label class="layui-form-label label-required-next">确认密码：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="password" name="repassword" value="" placeholder="请输入确认密码" lay-verify="{if !isset($info.id)}required{/if}" lay-vertype="tips" lay-reqtext="请输入确认密码" autocomplete="off" class="layui-input ">
                        {if isset($info.id)}
                        <p class="help-block">不填密码则不修改密码！！！</p>
                        {/if}
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="text" name="phone" value="" placeholder="请输入手机号" lay-verify="" lay-vertype="tips" lay-reqtext="请输入手机号" autocomplete="off" class="layui-input ">
                    </div>
                    <label class="layui-form-label ">邮箱：</label>
                    <div class="layui-input-inline input-custom-width" style="">
                        <input type="text" name="email" value="" placeholder="管理员邮箱" lay-verify="" lay-vertype="tips" lay-reqtext="请输入管理员邮箱" autocomplete="off" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生日：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="birthday" id="test1" placeholder="yyyy-MM-dd">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">性别：</label>
                    <div class="layui-input-inline">
                        <select name="sex" lay-verify="required" >
                            <option value="0" >男</option>
                            <option value="1" >女</option>
                            <option value="2" >保密</option>
                        </select>
                    </div>

                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="radio" name="status" value="1" title="正常" lay-filter=""  checked>
                        <input type="radio" name="status" value="2" title="拉黑" lay-filter="" >
                    </div>

                    <div class="layui-form-mid layui-word-aux"></div>
                </div>

                <div class="layui-form-item layui-layout-admin " style="width: 100%">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0px;text-align: center;">
                            <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>


<script>
    layui.use(['element', 'form', 'jquery','lucky','upload','laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var upload = layui.upload;
        var laydate = layui.laydate;

        //表单赋值
        var info = {:json_encode($info)};
        form.val("form",info);

        //常规用法
        laydate.render({
            elem: '#test1'
        });

        //图片上传
        upload.render({
            elem:'#editimg'
            ,url: "{:url('common/UpImg')}" //图片上传地址
            ,accept: 'images' //
            ,acceptMime: 'image/*'
            ,size: 1024*12
            ,before:function (res) {
                loading = layer.load(2, {
                    shade: [0.2, '#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(data){
                layer.close(loading);
                if (data.code==1){
                    layer.msg(data.msg, {icon: 1, time: 1000},function () {
                        $("#show_id").attr("src",data.data.thumb_path);
                        $("#avatar").val(data.data.thumb_path);
                    });
                } else {
                    layer.msg(data.msg, {icon: 5, time: 1000});
                }
            }
            ,error:function (red) {
                layer.close(loading);
                layer.msg("网络错误", {icon: 5, time: 1500});
            }
        });

        form.on('submit(add)', function (data) {
            lucky.FormSubmit("{:url('addAdmin')}",data.field,true);
            return false;
        });
    })
</script>

{/block}

